<template>
	<m-page :pageData="pageData">
		<view class="" slot="content">
			<m-form 
			:list="formList" 
			labelPosition="left" 
			:labelWidth="80"
			:classes="'wRight80'"
			@submit="submit"
			></m-form>
			<m-popup :show="popup.show" :okTxt="okTxt" :footer="true" @close="closeDetail" @sure="sureDetail">
				<view class="popup-detail">
					{{popup.text}}
				</view>
			</m-popup>
		</view>
	</m-page>
</template>

<script>
	export default {
		data() {
			return {
				popup:{
					show:false,
					text:'',
					taxRatio:0
				},
				disabled:false,
				okTxt:'确定',
				pageData:{
					showBrand:true,
					title:'实名认证',
					tips:'realNameAuthenticationRule'
				},
				formList:[
					{
						label:'姓名',
						placeholder:'请输入您的真实姓名',
						tag:'real_name',
						type:'input',
						classes:'wauto4 w192',
						required:true,
						rules:{
							type: 'string',
							required: true,
							message: '请输入正确的真实姓名',
							// trigger: ['blur', 'change'],
							// validator: (rule, value, callback) => {
							// 	// 上面有说，返回true表示校验通过，返回false表示不通过
							// 	// uni.$u.test.mobile()就是返回true或者false的
							// 	return uni.$u.test.email(value);
							// },
						},
					},
					{
						label:'身份证号',
						placeholder:'输入您的身份证号',
						tag:'id_card_number',
						type:'ident',
						classes:'wauto4 w192',
						message: '请输入正确的身份证号',
						required:true,
						rules:{
							type: 'string',
							required: true,
						},
					},
					{
						label:'证件照片',
						tag:'cardPhone',
						uploadCard:true,
						required:true,
						classes:'noBorder wauto4 ',
						
					},
					{
						errorMsg:true,
						classes:'noBorder ml80',
						text:'认证后不可修改，请务必确保为本人信息，如冒用他人信息会导致无法结算'
					},
					{
						button:true,
						disabled:false,
						submit:true,
						func:'submit',
						btn:'立即提交',
						btnStyle:{
							color:'#fff',fontSize:'28rpx',
							background:'#16b7ff',borderRadius:'5rpx',
						},
						classes:'noBorder  w145'
					},
				],
			};
		},
		onLoad() {
			let sys = uni.getSystemInfoSync()
			if(sys.screenWidth < 1024){
				this.formList[2].classes = 'noBorder noBorder-flexstart ';
				this.formList[3].classes = 'noBorder';
				this.formList[4].classes = 'noBorder ';
				this.formList[0].classes = 'noBorder ';
				this.formList[0].borderBottom = true;
				this.formList[1].borderBottom = true;
				this.formList[1].classes = 'noBorder ';
			}
			if(this.loginInfo.is_authentication == 1){//已实名
				this.formList = this.formList.slice(0,2)
				this.formList[0].required = false;
				this.formList[1].required = false;
				this.formList = this.formList.map(item =>{
					item.classes= "noBorder "
					item.disabled = true;
					item.value = this.loginInfo[item.tag]
					return item
				})
			}
		},
		methods:{
			
			submit(val){
				if(!this.utils.rules.idcard.test(val.id_card_number)){
					uni.showToast({
						title:'请填写正确的身份证！',
						icon:'none',
					})
					return
				}else{
					if(this.utils.idCard(val.id_card_number,3) < 16){
						uni.showToast({
							title:'请注意，仅16周岁及以上才可以使用本网站进行实名认证并工作！',
							icon:'none',
						})
						return
					}
				}
				let par = {
					"up_type": "1",
					...val

				}
				this.$api.update_user_settings(par).then(res =>{
					if(res.code == 200){
						uni.showToast({
							title:'修改成功！',
							icon:'none',
						})
						setTimeout(()=>{
							this.utils.goBack()
						},1500)
					}else{
						this.showPopup(res.message)
						// uni.showToast({
						// 	title:res.message,
						// 	icon:'none',
						// })
					}
				})
				
			},
			closeDetail(){
				this.popup.show = false;
			},
			showPopup(txt){
				this.popup.text = txt
				this.popup.show = true;
			},
		}
	}
</script>

<style lang="scss">

</style>
